package cn.hdustea.shopNavigation.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import cn.hdustea.shopNavigation.MainActivity
import cn.hdustea.shopNavigation.NavigationActivity
import cn.hdustea.shopNavigation.R
import cn.hdustea.shopNavigation.entity.Food
import cn.hdustea.shopNavigation.entity.IndoorPlanBean
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import kotlinx.android.synthetic.main.item_list_food.view.*

/**
 * <pre>
 *     author : HuQiang
 *     time   : 2020/09/19
 *     desc   :
 *     version: 1.0
 * </pre>
 */
class FoodItemAdapter(layoutResId: Int, parentContext: Context) :
        BaseQuickAdapter<Food, BaseViewHolder>(layoutResId), LoadMoreModule {

    val pContext = parentContext

    private val OPTIONS: RequestOptions = RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop()
            .dontAnimate()

    override fun convert(holder: BaseViewHolder, item: Food) {
        val rootView = holder.itemView
        Glide.with(context)
                .load(item.picurl)
                .apply(OPTIONS)
                .into(rootView.im_item_icon)
        rootView.rt_bar.rating = item.stars
        rootView.tv_restaurant_name.text = item.name
        if (item.consume_per == 0) {
            rootView.food_average_price.visibility = View.GONE
        } else {
            rootView.food_average_price.text = String.format(context.resources.getString(R.string.food_price), item.consume_per)
            rootView.food_average_price.visibility = View.VISIBLE
        }
        rootView.food_type.text = item.tag
        rootView.food_location.text = item.address

        rootView.to_navigation1.setOnClickListener {
            val intent  = Intent(pContext, MainActivity::class.java)
            intent.putExtra("searchText", rootView.tv_restaurant_name.text.toString())
            pContext.startActivity(intent)

        }



        Glide.with(context).load(R.drawable.ic_navigation).apply(OPTIONS).into(rootView.to_navigation1)

    }

}